package edu.uj.petri.model;

import edu.uj.petri.commands.Memento;

/**
 * @author Piotrek
 */
class NormalArcObjectImpl extends NormalArcImpl {
    private int weight;

    private ObjectModel model;

    private ArcObjectImpl arcImpl;

    public NormalArcObjectImpl(ObjectModel model) {
        arcImpl = new ArcObjectImpl(model);
        this.model = model;
        weight = 0;
    }

    public int getWeight() {
        return weight;
    }

    public void setWeight(int weight) {
        this.weight = weight;
    }

    /**
     * stores internal state in a memento
     */
    public Memento getMemento() {
        return new ArcMemento(weight);
    }

    /**
     * restores internal state of object to state stored in the memento
     */
    public void applyMemento(Memento memento) {
        if (!(memento instanceof ArcMemento))
            throw new IllegalArgumentException("invalid memento");
        ArcMemento am = (ArcMemento)memento;
        this.weight = am.weight;
    }

    public ArcImpl getArcImpl() {
        return arcImpl;
    }
    
    private static final long serialVersionUID = -3236959007680997182L;
    
    static class ArcMemento extends Memento {
        private int weight;
        
        ArcMemento(int weight) {
            this.weight = weight;
        }
    }
}
